/**
 * @param {number[]} prices
 * @return {number}
 */

var maxProfit = function(prices) {
    let max=0;
    let min=Number.MAX_SAFE_INTEGER;
    console.log(prices)
    for(let i=0;i<prices.length-1;i++){
        console.log(i,prices[i],min,max)
        // const next=prices[j];
        const cur=prices[i]
        min=Math.min(min,prices[i])
        max=Math.max(cur-min,max)
        console.log(i,prices[i],min,max)  
        
      
    }
    return max;
};

maxProfit([7,1,5,3,6,4])


var maxProfit2 = function(prices) {
    let max=0;
    if(prices.length<1){
        return;
    }
    console.log(prices)
    for(let i=0;i<prices.length-1;i++){
       for(let j=i+1;j<prices.length;j++){
        const next=prices[j];
        const cur=prices[i]
        console.log(i,next,cur,max,'b')
        if(next && next>cur){
            max=Math.max(next-cur,max)
            
        }
       }
    }
    return max;
};
